import java.math.BigDecimal;
import java.math.RoundingMode;

public class FruitShop {
    // 水果单价定义
    private static final BigDecimal APPLE_PRICE = BigDecimal.valueOf(8);
    private static final BigDecimal STRAWBERRY_PRICE = BigDecimal.valueOf(13);
    private static final BigDecimal MANGO_PRICE = BigDecimal.valueOf(20);

    // 优惠门槛和金额
    private static final BigDecimal DISCOUNT_THRESHOLD = BigDecimal.valueOf(100);
    private static final BigDecimal DISCOUNT_AMOUNT = BigDecimal.valueOf(10);

    /**
     * 计算顾客A购买苹果和草莓的总价
     * @param applePounds 苹果斤数
     * @param strawberryPounds 草莓斤数
     * @return 总价
     */
    public static BigDecimal calculatePriceForCustomerA(int applePounds, int strawberryPounds) {
        validateNonNegative(applePounds, "苹果斤数");
        validateNonNegative(strawberryPounds, "草莓斤数");

        return APPLE_PRICE.multiply(BigDecimal.valueOf(applePounds))
                .add(STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(strawberryPounds)));
    }

    /**
     * 计算顾客B购买苹果、草莓和芒果的总价
     * @param applePounds 苹果斤数
     * @param strawberryPounds 草莓斤数
     * @param mangoPounds 芒果斤数
     * @return 总价
     */
    public static BigDecimal calculatePriceForCustomerB(int applePounds, int strawberryPounds, int mangoPounds) {
        validateNonNegative(applePounds, "苹果斤数");
        validateNonNegative(strawberryPounds, "草莓斤数");
        validateNonNegative(mangoPounds, "芒果斤数");

        return APPLE_PRICE.multiply(BigDecimal.valueOf(applePounds))
                .add(STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(strawberryPounds)))
                .add(MANGO_PRICE.multiply(BigDecimal.valueOf(mangoPounds)));
    }

    /**
     * 计算顾客C购买苹果、草莓（打8折）和芒果的总价
     * @param applePounds 苹果斤数
     * @param strawberryPounds 草莓斤数
     * @param mangoPounds 芒果斤数
     * @return 总价
     */
    public static BigDecimal calculatePriceForCustomerC(int applePounds, int strawberryPounds, int mangoPounds) {
        validateNonNegative(applePounds, "苹果斤数");
        validateNonNegative(strawberryPounds, "草莓斤数");
        validateNonNegative(mangoPounds, "芒果斤数");

        BigDecimal discountedStrawberryPrice = STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(0.8));
        return APPLE_PRICE.multiply(BigDecimal.valueOf(applePounds))
                .add(discountedStrawberryPrice.multiply(BigDecimal.valueOf(strawberryPounds)))
                .add(MANGO_PRICE.multiply(BigDecimal.valueOf(mangoPounds)));
    }

    /**
     * 计算顾客D购买苹果、草莓和芒果的总价，并应用满100减10的优惠
     * @param applePounds 苹果斤数
     * @param strawberryPounds 草莓斤数
     * @param mangoPounds 芒果斤数
     * @return 总价
     */
    public static BigDecimal calculatePriceForCustomerD(int applePounds, int strawberryPounds, int mangoPounds) {
        validateNonNegative(applePounds, "苹果斤数");
        validateNonNegative(strawberryPounds, "草莓斤数");
        validateNonNegative(mangoPounds, "芒果斤数");

        BigDecimal total = APPLE_PRICE.multiply(BigDecimal.valueOf(applePounds))
                .add(STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(strawberryPounds)))
                .add(MANGO_PRICE.multiply(BigDecimal.valueOf(mangoPounds)));

        if (total.compareTo(DISCOUNT_THRESHOLD) >= 0) {
            total = total.subtract(DISCOUNT_AMOUNT);
        }

        return total;
    }

    /**
     * 参数校验：确保斤数非负
     * @param value 参数值
     * @param name 参数名称
     */
    private static void validateNonNegative(int value, String name) {
        if (value < 0) {
            throw new IllegalArgumentException(name + "不能为负数");
        }
    }

    public static void main(String[] args) {
        // 验证函数计算结果的正确性
        System.out.println("Customer A: " + calculatePriceForCustomerA(5, 3)); // 应输出 79
        System.out.println("Customer B: " + calculatePriceForCustomerB(4, 2, 1)); // 应输出 78
        System.out.println("Customer C: " + calculatePriceForCustomerC(3, 4, 2)); // 应输出约 105.6
        System.out.println("Customer D: " + calculatePriceForCustomerD(6, 5, 3)); // 应输出 163

        // 边界测试
        System.out.println("Zero pounds: " + calculatePriceForCustomerA(0, 0)); // 输出 0
        try {
            calculatePriceForCustomerA(-1, 2); // 抛出异常
        } catch (IllegalArgumentException e) {
            System.out.println("捕获异常: " + e.getMessage());
        }
    }
}
